package com.leyou.upload.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 初始化Oss需要的对象
 */
@Configuration
public class OssConfig {

    //OssProperties ossProps: 自动从IOC容器中获取该类型的对象注入进来
    @Bean
    public OSS createOss(OssProperties ossProps){
        return new OSSClientBuilder().build(
                ossProps.getEndpoint(),
                ossProps.getAccessKeyId(),
                ossProps.getAccessKeySecret());
    }
}
